/**
 * @Date 2023-02-05 11:08:52
 * @Remark
 */

// react
import React, { useEffect } from "react";
// lib
import { useLocation, useNavigate } from "react-router-dom";
// scroll
// components & widget
// style
// config
import { ROUTE_MODE, ROUTE_MAIN_VIEW } from "project/config";
// script & methods & public
import { getCodeFromPath } from "routes/format";
// store
import { observer } from "mobx-react";
import { dataState, userState } from "state/global";
// controller
// interface
// 其它

function PageAccessChecker() {
  const location = useLocation();
  const navigate = useNavigate();

  useEffect(() => {
    const code = getCodeFromPath(location.pathname);
    const accessList = userState.getAccount().menuList;
    console.log("l-----",dataState.routeItemList)
    const have = accessList.find((el) => code.includes(el.menuCode));

    if (ROUTE_MODE === "static" || have || ["main:system:403"].includes(code)) {
      // 静态路由/有权限/错误页的情况都不做操作
    } else {
      // navigate(`/${ROUTE_MAIN_VIEW}/system/403`, {
      //   replace: true,
      // });
    }
    return () => {
      //
    };
  }, [location, navigate]);

  return (
    <span
      style={{
        display: "none",
      }}
    />
  );
}

export default observer(PageAccessChecker);
